package com.neulogistics.contrib.warehouse.domain.model.enumeration;

import com.neulogistics.contrib.warehouse.domain.exception.WarehouseDomainException;
import com.neulogistics.infrastructure.common.serviceresult.ErrorCode;
import com.neulogistics.infrastructure.ddd.domain.seedwork.Enumeration;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class CirculationStatus extends Enumeration {
    public static final int In_Progress_Id = 0;
    public static final int Completed_Id = 1;
    public static final int Canceled_Id = 1;

    public static CirculationStatus In_Progress = new CirculationStatus(In_Progress_Id, "In_Progress");
    public static CirculationStatus Completed = new CirculationStatus(Completed_Id, "Completed");
    public static CirculationStatus Canceled = new CirculationStatus(Canceled_Id, "Canceled");

    protected CirculationStatus(int id, String name) {
        super(id, name);
    }

    private static List<CirculationStatus> list = Arrays.asList(In_Progress, Completed, Canceled);

    public static List<CirculationStatus> getList(){return list;}

    public static CirculationStatus fromName(String name) throws WarehouseDomainException {
        Optional<CirculationStatus> optional = list.stream().filter(p -> p.name.equals(name)).findFirst();

        if (optional.isPresent()){
            return optional.get();
        }
        else {
            throw new WarehouseDomainException(
                    ErrorCode.OPERATION_ERROR,
                    String.format("Possible values for {%s}: %s",
                            CirculationStatus.class.getSimpleName(),
                            list.stream()
                                    .map(p -> p.name)
                                    .collect(Collectors.joining(",")))
            );
        }
    }




    @Override
    public int compareTo(Object o) {
        return 0;
    }
}
